package br.com.loja.view.swing.model;

import br.com.loja.util.i18n.Language;
import java.awt.event.ActionListener;
import javax.swing.JToolBar;

/**
 * @brief Classe SearchToolbar
 * @author David Luiz
 * @date 10/12/2014
 */
public class SearchToolbar extends JToolBar {

    private javax.swing.JButton btBuscar;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.Box.Filler filler3;
    private javax.swing.JLabel lblChave;
    private javax.swing.JTextField txtChave;
    private Language language;

    public SearchToolbar() {
        initComponents(null);
    }

    public SearchToolbar(ActionListener listener) {
        initComponents(listener);
    }

    private void initComponents(ActionListener listener) {
        language = Language.getInstance();

        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 32767));
        lblChave = new javax.swing.JLabel();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 32767));
        txtChave = new javax.swing.JTextField();
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 0), new java.awt.Dimension(12, 32767));
        btBuscar = new javax.swing.JButton();

        setFloatable(false);
        setRollover(true);
        add(filler2);

        lblChave.setText(language.getString("code"));
        add(lblChave);
        add(filler1);

        txtChave.setMaximumSize(new java.awt.Dimension(150, 28));
        txtChave.setMinimumSize(new java.awt.Dimension(150, 28));
        txtChave.setPreferredSize(new java.awt.Dimension(150, 28));
        add(txtChave);
        add(filler3);

        btBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/img/Deep_Search.png")));
        btBuscar.setFocusable(false);
        btBuscar.setActionCommand("search");
        btBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btBuscar.addActionListener(listener);
        add(btBuscar);
    }

    public String getKey() {
        return this.txtChave.getText();
    }

}
